<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 连续差相同的数字 -->
    <script>
      var numsSameConsecDiff = function (n, k) {
        const ans = []
        const dfs = (i, cur) => {
          if (i === n) {
            return ans.push(cur.join('') * 1)
          }
          const pre = cur[cur.length - 1]
          if (pre + k >= 0 && pre + k <= 9) {
            dfs(i + 1, [...cur, pre + k])
          }
          // pre - k !== pre + k 是做一个去重
          if (pre - k !== pre + k && pre - k >= 0 && pre - k <= 9) {
            dfs(i + 1, [...cur, pre - k])
          }
        }
        for (let num = 1; num <= 9; num++) {
          dfs(1, [num])
        }
        return ans
      }
      console.log(numsSameConsecDiff(3, 7))
    </script>
  </body>
</html>
